fsck: add argument --add-tombstones
authorGiuseppe Scrivano <gscrivan@redhat.com>
Wed, 28 Oct 2015 13:23:35 +0000 (14:23 +0100)
committerGiuseppe Scrivano <gscrivan@redhat.com>
Tue, 3 Nov 2015 08:53:38 +0000 (09:53 +0100)
It is used to create tombstones for missing commits

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
doc/ostree-fsck.xml
src/ostree/ot-builtin-fsck.c

index 68107f5352ecf83378af4a0654264398e6c4bff4..2cae92cfb236fb3d5e1017b216678c15576e8e04 100644 (file)
@@ -78,6 +78,13 @@ Boston, MA 02111-1307, USA.
                    Remove corrupted objects.
                 </para></listitem>
             </varlistentry>
+
+            <varlistentry>
+                <term><option>--add-tombstones</option></term>
+                <listitem><para>
+                   Add tombstone commit for referenced but missing commits.
+                </para></listitem>
+            </varlistentry>
         </variablelist>
     </refsect1>
 
index 69bb2e46d953c70a06860db4f225fe4cf4f9a66d..d16ead840b5523e1d4feaefb67b99ff63b71c986 100644 (file)
 
 static gboolean opt_quiet;
 static gboolean opt_delete;
+static gboolean opt_add_tombstones;
 
 static GOptionEntry options[] = {
+  { "add-tombstones", 0, 0, G_OPTION_ARG_NONE, &opt_add_tombstones, "Add tombstones for missing commits", NULL },
   { "quiet", 'q', 0, G_OPTION_ARG_NONE, &opt_quiet, "Only print error messages", NULL },
   { "delete", 0, 0, G_OPTION_ARG_NONE, &opt_delete, "Remove corrupted objects", NULL },
   { NULL }
@@ -246,7 +248,7 @@ ostree_builtin_fsck (int argc, char **argv, GCancellable *cancellable, GError **
   guint n_partial = 0;
   g_autoptr(GHashTable) objects = NULL;
   g_autoptr(GHashTable) commits = NULL;
-
+  g_autoptr(GPtrArray) tombstones = NULL;
   context = g_option_context_new ("- Check the repository for consistency");
 
   if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error))
@@ -264,6 +266,9 @@ ostree_builtin_fsck (int argc, char **argv, GCancellable *cancellable, GError **
   
   g_hash_table_iter_init (&hash_iter, objects);
 
+  if (opt_add_tombstones)
+    tombstones = g_ptr_array_new_with_free_func (g_free);
+
   while (g_hash_table_iter_next (&hash_iter, &key, &value))
     {
       GVariant *serialized_key = key;
@@ -281,6 +286,9 @@ ostree_builtin_fsck (int argc, char **argv, GCancellable *cancellable, GError **
           if (commitstate & OSTREE_REPO_COMMIT_STATE_PARTIAL)
             {
               n_partial++;
+
+              if (opt_add_tombstones)
+                g_ptr_array_add (tombstones, g_strdup (checksum));
             }
           else
             g_hash_table_insert (commits, g_variant_ref (serialized_key), serialized_key);
@@ -297,7 +305,33 @@ ostree_builtin_fsck (int argc, char **argv, GCancellable *cancellable, GError **
                                             cancellable, error))
     goto out;
 
-  if (n_partial > 0)
+  if (opt_add_tombstones)
+    {
+      guint i;
+      if (tombstones->len)
+        {
+          GError *temp_error = NULL;
+          gboolean tombstone_commits = FALSE;
+          GKeyFile *config = ostree_repo_get_config (repo);
+          tombstone_commits = g_key_file_get_boolean (config, "core", "tombstone-commits", &temp_error);
+          /* tombstone_commits is FALSE either if it is not found or it is really set to FALSE in the config file.  */
+          if (!tombstone_commits)
+            {
+              g_clear_error (&temp_error);
+              g_key_file_set_boolean (config, "core", "tombstone-commits", TRUE);
+              if (!ostree_repo_write_config (repo, config, error))
+                goto out;
+            }
+        }
+      for (i = 0; i < tombstones->len; i++)
+        {
+          const char *checksum = tombstones->pdata[i];
+          g_print ("Adding tombstone for commit %s\n", checksum);
+          if (!ostree_repo_delete_object (repo, OSTREE_OBJECT_TYPE_COMMIT, checksum, cancellable, error))
+            goto out;
+        }
+    }
+  else if (n_partial > 0)
     {
       g_print ("%u partial commits not verified\n", n_partial);
     }